<!DOCTYPE html>
<html>
<head>
	<div th:include="base-libs-easyui :: base-libs-easyui" />
<title>机构二级科室信息</title>
<style type="text/css">
	body {
		padding: 0px 10px;
	}
	.form-table input{
		width: 500px;
		padding-left: 4px;
	}
	.form-table select{
		width: 504px!important;
	}
</style>
</head>
<script th:inline="javascript">
    /**读取request中的初始化数据*/
    var requestData = [[${requestData}]];
</script>
<script type="text/javascript">
	$(function() {
		initView();
        initData();
	});

	function initData() {
	    /*上级科室信息*/
	    var SJKSXX = StoreCache.removeCache("curr_sjksxx");
	    $("#formJgKsxx").data("SJKSXX", SJKSXX);
	    setSjksxx();
	    /*修改的科室信息*/
	    var updatedJgksxx = StoreCache.removeCache("curr_jgksxx_second");
        if(updatedJgksxx)
        {
            $("#formJgKsxx").data("updatedJgksxx", updatedJgksxx);
            /*修改禁用科室代码*/
            $("#KSDM").attr("readonly", true);
            setData();
        }
	}

	function setSjksxx(){
        var SJKSXX = $("#formJgKsxx").data("SJKSXX");
        var YLJGMC = SJKSXX["YLJGMC"];
        $("#YLJGMC").val(YLJGMC);
        var PTJGID = SJKSXX["PTJGID"];
        $("#PTJGID").val(PTJGID);
        var KSMC = SJKSXX["KSMC"];
        $("#SJKSMC").val(KSMC);
        var KSDM = SJKSXX["KSDM"];
        $("#SJKSDM").val(KSDM);
	}

	function setData(){
        var updatedJgksxx = $("#formJgKsxx").data("updatedJgksxx");
        $(".form-control").each(function(){
            var name = $(this).attr("name");
            if(!StringUtils.isEmpty(name)){
                var value = updatedJgksxx[name];
                $(this).QuickField("setData", value);
			}
        })
	}

	function initView() {
		$("#formJgKsxx").attr("action", contextRoot + "/ksxx/saveKsxx");
		$("#btnSave").on("click", btnSaveHandler);
        $("#btnClose").on("click", btnCloseHandler);
	}

	function btnSaveHandler(){
        if($(".form-control").QuickValidate())
        {
            var method = "add";
            var old = $("#formJgKsxx").data("updatedJgksxx");
            if(old){
                method = "update";
			}
            var params = {method: method};
            /*获取是否特色科室*/
            params["SFTSKS"] = "0";
            /*默认二级科室*/
            params["JB"] = "2";

            $.QuickRemote.AjaxFiledFormSubmit("formJgKsxx", saveHandler, params);
        }
	}
	function saveHandler(result){
        var state = result["state"];
        if(state)
        {
            $.QuickAlert.alertNormal("保存成功", {callback: function(){
                $("#btnClose").trigger("click");
            }});
        }
        else
        {
            var info = result["info"];
            $.QuickAlert.alertFail({content: info["faultInfo"]});
        }
	}

	/**返回按钮*/
	function btnCloseHandler() {
        parent.layer.closeAll();
	}
</script>

<body class="easyui-layout">
	<div region="center" style="border: none;">
		<form id="formJgKsxx">
			<table class="form-table">
				<tr>
					<td class="td-text">
						<label>机构名称</label>
					</td>
					<td class="td-content">
						<input id="YLJGMC" type="text" class="form-control" readonly="readonly">
						<input id="PTJGID" name="PTJGID" class="form-control" style="display: none;">
					</td>
				</tr>
				<tr>
					<td class="td-text">
						<label>一级科室名称</label>
					</td>
					<td class="td-content">
						<input id="SJKSMC" type="text" class="form-control" readonly="readonly">
						<input id="SJKSDM" name="SJKSDM" type="text" class="form-control" style="display: none;">
					</td>
				</tr>
				<tr>
					<td class="td-text">
						<label>二级科室代码</label>
					</td>
					<td class="td-content">
						<input id="KSDM" name="KSDM" type="text" placeholder="二级科室代码"
							   quick-config="label:'二级科室代码', validateProxy:'notNull length', length: '64'"
							   class="form-control">
					</td>
				</tr>
				<tr>
					<td class="td-text">
						<label>二级科室名称</label>
					</td>
					<td class="td-content">
						<input id="KSMC" name="KSMC" type="text" placeholder="二级科室名称"
							   quick-config="label:'二级科室名称', validateProxy:'notNull length', length: '64'"
							   class="form-control">
					</td>
				</tr>
			</table>
		</form>
	</div>
	<div region="south" style="height: 41px; padding-top: 6px;">
		<button id="btnClose" type="button" style="margin-right: 10px; float: right;">关闭</button>
		<button id="btnSave" type="button" style="margin-right: 10px; float: right;">保存</button>
	</div>
</body>
</html>


